﻿using System.Threading;
using NUnit.Framework;

namespace AsyncLoggers.Tests
{
    /// <summary>
    /// Summary description for CommandProcessorTests
    /// </summary>
    [TestFixture]
    public class CommandProcessorTests
    {
        [Test]
        public void MakeSureDisposeWaitsUntilAllCommandsAreProcessed()
        {
            int commandsProcessed = 0;
            const int commandsToProcess = 10000;

            using (var commandProcessor = new CommandProcessor())
            {
                for (int i = 0; i < commandsToProcess; i++)
                {
                    commandProcessor.QueueCommand(
                        new ActionCommand(
                        ()=>
                            {
                                Interlocked.Increment(ref commandsProcessed);
                            }));
                }
            
            // calls into Dispose implicitly
            }

            Assert.AreEqual(commandsToProcess, commandsProcessed);
        }
    }
}